package com.cq.hd.admin.controller;

import com.cq.hd.admin.annotation.RequiresPermissionsDesc;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.product.api.TbLabelApi;
import com.cq.hd.product.api.dto.LabelPageDto;
import com.cq.hd.product.api.dto.LabelSaveDto;
import com.cq.hd.product.api.vo.LabelPageVo;
import com.cq.hd.product.api.vo.LabelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "标签管理相关接口")
@Slf4j
@RestController
@RequestMapping("/label")
public class TbLabelController {

    @Resource
    private TbLabelApi labelApi;

    @ApiOperation(value = "标签列表")
    @ApiImplicitParam(name = "labelPageDto", value = "实体", paramType = "query", dataType = "LabelPageDto")
    @ApiResponse(response = LabelPageVo.class, code = 200, message = "接口返回对象参数")
    @RequiresPermissions("operations:label:list")
    @RequiresPermissionsDesc(menu = {"运营管理", "标签管理"}, button = "列表")
    @GetMapping("/page")
    public Result<Page<LabelPageVo>> pageLabel(LabelPageDto labelPageDto) {
        return labelApi.pageLabel(labelPageDto);
    }

    @ApiOperation(value = "保存标签")
    @ApiImplicitParam(name = "labelPageDto", value = "实体", paramType = "body", dataType = "LabelPageDto")
    @RequiresPermissions("operations:label:save")
    @RequiresPermissionsDesc(menu = {"运营管理", "标签保存"}, button = "保存")
    @PostMapping("/save")
    public Result<LabelVo> saveLabel(@RequestBody LabelSaveDto labelSaveDto) {
        return labelApi.saveLabel(labelSaveDto);
    }

    @ApiOperation(value = "删除标签")
    @RequiresPermissions("operations:label:delete")
    @RequiresPermissionsDesc(menu = {"运营管理", "标签删除"}, button = "删除")
    @PostMapping("/delete/{id}")
    public Result<Void> deleteLabel(@PathVariable("id") Long id) {
        return labelApi.deleteLabel(id);
    }

}
